//
//  WmcMediaRecognitionAPI.swift
//  YPWatermarkCamera
//
//  Created by 周诗松 on 2022/10/25.
//

import Foundation
import RxSwift
import YPNetwork

struct WmcMediaRecognitionAPI {
    enum RecognitionType: Int {
        /// 数钢筋
        case rebar = 0
        /// 数钢管
        case pipe
    }

    static func recognizeQuantity(type: RecognitionType, resourceId: String, imgUrl: String) -> Observable<[WmcMediaRecognitionModel]> {
        let params: [String: Any] = ["entryId": YPWmcManager.shared.entry, "type": type.rawValue, "resourceId": resourceId, "url": imgUrl]

        return WmcMediaRequest.requestData(path: "/wmc/v1/intelligent/pipeCount", parameters: params) { request in
            request.method = .post
        }.parseListModelWithClass(WmcMediaRecognitionModel.self)
    }

    static func submitRecognitionData(resourceId: String, newResourceId: String, newUrl: String, isCorrected: Bool) -> Observable<YPNetworkResponse> {
        let params: [String: Any] = ["entryId": YPWmcManager.shared.entry, "originalResourceId": resourceId, "resourceId": newResourceId, "url": newUrl, "corrected": isCorrected]
        return WmcMediaRequest.requestData(path: "/wmc/v1/intelligent/confirm", parameters: params) { request in
            request.method = .post
        }
    }
}
